package com.tct.worktimeboard.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tct.worktimeboard.entity.WorkKind;
import com.tct.worktimeboard.mapper.WorkKindMapper;
import com.tct.worktimeboard.service.IWorkKindService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tct.worktimeboard.util.JsonUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liyongkui
 * @since 2021-02-22
 */
@Service
public class WorkKindServiceImpl extends ServiceImpl<WorkKindMapper, WorkKind> implements IWorkKindService {

    @Resource
    WorkKindMapper workKindMapper;

    @Override
    public JSONObject listPageWorKind(WorkKind workKind) {
        if(workKind.isPaged()){
            PageHelper.startPage(workKind.getPageNum(),workKind.getPageSize());
        }
        QueryWrapper<WorkKind> queryWrapper = new QueryWrapper<>();
        if(workKind.getWorkName() != null && !workKind.getWorkName().isEmpty()){
            queryWrapper.like("work_name",workKind.getWorkName());
        }
        List<WorkKind> list = workKindMapper.selectList(queryWrapper);
        PageInfo<WorkKind> info = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>();
        result.put("total",info.getTotal());
        result.put("rows",list);
        return JsonUtil.toJsonData(result);
    }
}
